package com.zlei.code.review;

import com.zlei.code.binaryTree.TreeNode;

import java.util.Stack;

/**
 * @Author leizhang76
 * @Date 2021/2/22 15:25
 */
public class Review {
    /**
     * 二叉树的前序递归遍历
     *
     * @param node
     */
    public void preOrder1(TreeNode node) {
        if (node != null) {
            System.out.println(node.val);
            preOrder1(node.left);
            preOrder1(node.right);
        }
    }

    /**
     * 二叉树的前序非递归遍历
     *
     * @param root
     */
    public void preOrder2(TreeNode root) {
        Stack<TreeNode> stack = new Stack<>();
        stack.push(root);
        while (!stack.isEmpty()) {
            TreeNode pop = stack.pop();
            System.out.println(pop.val);
            if (pop.right != null) {
                stack.push(pop.right);
            }
            if (pop.left != null) {
                stack.push(pop.left);
            }
        }
    }

    /**
     * 二叉树的中序递归遍历
     *
     * @param node
     */
    public void inOrder1(TreeNode node) {
        if (node != null) {
            inOrder1(node.left);
            System.out.println(node.val);
            inOrder1(node.right);
        }
    }

    /**
     * 二叉树的中序非递归遍历
     *
     * @param node
     */
    public void inOrder2(TreeNode node) {


    }


}
